package com.cade.agriculturemall.view.personalCenter.discount.myDiscountFragment;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cade.agriculturemall.R;
import com.cade.agriculturemall.base.BaseAdapter;
import com.cade.agriculturemall.base.BaseViewHolder;
import com.cade.agriculturemall.model.Ticket;
import com.cade.agriculturemall.utils.ConverUtil;
import com.cade.agriculturemall.view.shoppingCar.settlement.SettlementViewModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hshunxin on 2018/2/24.
 */

public class MyDiscountAdapter extends BaseAdapter<BaseViewHolder> {
    private final Context context;
    private List<MyDiscountViewHolder> models = new ArrayList<>();

    public MyDiscountAdapter(Context context, List<MyDiscountViewHolder> models) {
        this.context = context;
        this.models = models;
    }

    @Override
    public void onBindViewHolderWrapper(BaseViewHolder holder, int position) {
        int viewType = getItemViewType(position);
        switch (viewType) {
            case MyDiscountViewHolder.TYPE_ACTIVE:
            case MyDiscountViewHolder.TYPE_NO_ACTIVE:
                TextView tvTitle = holder.findViewById(R.id.discount_title_tv);
                TextView tvContent = holder.findViewById(R.id.discount_content_tv);
                TextView tvTime = holder.findViewById(R.id.discount_time_tv);
                Ticket entity = (Ticket) models.get(position).getObject();
                tvTitle.setText("￥" + entity.getMoney() + "元" + entity.getType());
                tvContent.setText(entity.getContent());
                tvTime.setText("截止日期:" + ConverUtil.dateToStrLong(entity.getStartTime()) + "-" + ConverUtil.dateToStrLong(entity.getEndTime()));
                break;
            case MyDiscountViewHolder.TYPE_LINE:
                break;
        }

    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseViewHolder v = null;
        switch (viewType) {
            case MyDiscountViewHolder.TYPE_ACTIVE:
                v = new BaseViewHolder(parent, R.layout.my_discount_item);
                break;
            case MyDiscountViewHolder.TYPE_LINE:
                v = new BaseViewHolder(parent, R.layout.my_discount_item_line);
                break;
            case MyDiscountViewHolder.TYPE_NO_ACTIVE:
                v = new BaseViewHolder(parent, R.layout.my_discount_item_no_active);
                break;
        }
        return v;
    }


    @Override
    public int getItemViewType(int position) {
        return models.get(position).getType();
    }

    @Override
    public int getItemCount() {
        return models.size();
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

}
